''' Mission 8 -- Answer Bot Solution with traversing a list with a for loop ''' from codex import * import random from time import sleep answers = ["The odds are yes", "It is not in the stars", "Go for the gold!", "Today is your day", "Stay home and read", "Have an adventure"] # === Functions # new function with a for loop def pixel_colors(delay): for pix in range(4): pixels.set(pix, random.choice(COLOR_LIST)) sleep(delay) # original function with four function calls # def pixel_colors(delay): # pixels.set(0, random.choice(COLOR_LIST)) # pixels.set(1, random.choice(COLOR_LIST)) # pixels.set(2, random.choice(COLOR_LIST)) # pixels.set(3, random.choice(COLOR_LIST)) # sleep(delay) def slideshow(): for item in answers: display.print(item) sleep(1) # === Main Program while True: delay = random.randrange(1, 10)/10 pixel_colors(delay) if buttons.was_pressed(BTN_A): display.clear() display.print(random.choice(answers)) if buttons.was_pressed(BTN_U): slideshow() if buttons.was_pressed(BTN_B): break # === end display.clear() pixels.off()